import { useToastContext } from "@/context/toast-context"
import type { Options } from "@/context/toast-context"

/**
 * 自定义 Toast Hook
 */
export const useToast = () => {
  const toast = useToastContext()

  if (!toast) {
    throw new Error("useToast must be used within a ToastProvider")
  }

  /**
   * 成功 Toast
   */
  const success = (options: Options) => {
    toast.showSuccess({
      title: options.title,
      description: options.description
    })
  }

  /**
   * 错误 Toast
   */
  const error = (options: Options) => {
    toast.showError({
      title: options.title,
      description: options.description
    })
  }

  /**
   * 信息 Toast
   */
  const info = (options: Options) => {
    toast.showInfo({
      title: options.title,
      description: options.description
    })
  }

  return {
    success,
    error,
    info
  }
}
